package application;

import io.netty.channel.Channel;
import network.websocket.WSServerSender;

/**
 * 请求处理器抽象
 * 用于处理完成后将响应发送给请求的客户端
 *
 * @author wyl
 */
public abstract class RequestHandler<TRequest, TResponse> {

    /**
     * 处理一个请求返回其响应
     *
     * @param request        请求实体
     * @param requestChannel 请求信道
     * @return
     */
    public abstract TResponse handle(TRequest request, Channel requestChannel);

    public void requestHandleCore(TRequest request, Channel requestChannel) {
        TResponse response = handle(request, requestChannel);
        if (response != null) {
            WSServerSender.send(requestChannel, response);
        }
    }


}


